<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/templates/modelo.xhtml">

	<ui:define name="centro">
		<h:form id="frmRec">
			<p:panel header="Recursos">
				<h:panelGrid columns="2">
					<h:outputLabel for="txtRecDesc" value="Descrição:" />
					<p:inputText id="txtRecDesc"
						value="#{recursoBacking.recurso.descricao}" size="40"
						maxlength="50" required="true"
						requiredMessage="O campo Descrição é obrigatório!" />

					<h:outputLabel for="txtRecQtde" value="Quantidade (0 - 10):" />
					<p:inputText id="txtRecQtde"
						value="#{recursoBacking.recurso.quantidade}" size="10"
						maxlength="2" required="true"
						requiredMessage="O campo Quantidade é obrigatório!"
						validatorMessage="Informe um valor entre 0 e 10 para o campo Quantidade">
						<f:validateLongRange minimum="0" maximum="10" />
					</p:inputText>
				</h:panelGrid>

				<h:panelGrid columns="4">
					<p:commandButton icon="ui-icon-plus" type="submit"
						actionListener="#{recursoBacking.novo}" process="@this"
						update="@form" />
					<p:commandButton icon="ui-icon-disk" type="submit"
						actionListener="#{recursoBacking.salvar}"
						process="@this, :frmRec:txtRecDesc, :frmRec:txtRecQtde"
						update="@form" />
				</h:panelGrid>

				<p:separator />

				<h:panelGrid columns="3">
					<h:outputLabel for="txtRecPesquisa" value="Descrição:" />
					<p:inputText id="txtRecPesquisa" size="40" maxlength="50"
						value="#{recursoBacking.pesquisa}" />
					<p:commandButton icon="ui-icon-search" type="submit"
						process="@this, :frmRec:txtRecPesquisa"
						actionListener="#{recursoBacking.buscar}"
						update=":frmRec:dtTblRec" />
				</h:panelGrid>

				<p:dataTable id="dtTblRec" emptyMessage=""
					value="#{recursoBacking.recursos}" var="rec" paginator="true"
					rows="5">

					<p:column>
						<f:facet name="header">
							<h:outputText value="Descrição" />
						</f:facet>
						<h:outputText value="#{rec.descricao}" />
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="Qtde" />
						</f:facet>
						<h:outputText value="#{rec.quantidade}" />
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="Opções" />
						</f:facet>
						<p:commandButton icon="ui-icon-folder-open" process="@this"
							actionListener="#{recursoBacking.selecionar}"
							update=":frmRec:txtRecDesc, :frmRec:txtRecQtde" type="submit" />
						<p:commandButton icon="ui-icon-trash" type="submit"
							onclick="confDlgRecExc.show()" process="@this"
							actionListener="#{recursoBacking.selecionar}" />
					</p:column>
				</p:dataTable>
			</p:panel>

			<p:confirmDialog appendToBody="true"
				message="Deseja excluir o recurso?" header="Recursos"
				severity="alert" widgetVar="confDlgRecExc">
				<p:commandButton value="Sim" oncomplete="confDlgRecExc.hide()"
					actionListener="#{recursoBacking.excluir}" process="@this"
					update="@form" />
				<p:commandButton value="Não" onclick="confDlgRecExc.hide()"
					type="button" />
			</p:confirmDialog>
		</h:form>
	</ui:define>
</ui:composition>


